import React, { Component, createRef } from 'react'
import Test from './Test'

export default class App extends Component {
  constructor(...args) {
    super(...args)
    console.log('1, constructor');
    this.state = {
      age: 25,
    }
    this.divRef = createRef()
  }

  render () {
    console.log('2, render')
    // !render 一定不要直接调用 setState
    // this.setState({ age: 18 })
    return (
      <div className='app' ref={this.diVRef}
        onClick={() => {
          this.setState({
            age: this.state.age + 1
          })
        }}
      >
        App <span>{this.state.age}</span>
      </div >
    )
  }
  componentDidMount () {
    // 发请求
    // 获取 DOM
    console.log(document.querySelector('.app').innerHTML)
    console.log('3, componentDidMount');
  }
  componentDidUpdate () {
    console.log('componentDidUpdate')
    console.log(document.querySelector('span').innerHTML)
  }
}
